package test.src.sqlConnect;

import java.sql.*;

public class DbCon {
    public static String url = "jdbc:mysql://10.69.100.248:3306/test2021";
    public static void main(String[] args) {
        try {
            Connection connection = DriverManager.getConnection(url, "root", "123456");
            if (connection != null) {
                System.out.println("连接成功！");
            } else {
                System.out.println("连接失败！");
                System.exit(0);
            }
            PreparedStatement sql = connection.prepareStatement("select * from student");
            sql.execute();
            ResultSet resultSet = sql.getResultSet();
            while (resultSet.next()) {
                System.out.println(resultSet.getString("sname"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
